//********************************************************************
//
//Authors : Vincent Joubert
//Project : How active am I
//Place   : Plymouth University
//Period  : from 10/06/2013 to 10/09/2013
//File    : accelero.h
//
// *******************************************************************


#ifndef __ACCELERO_H
#define __ACCELERO_H


#include <p18f46k22.h>
#include <i2c.h>


#define AddressMMA8451Q 0x1C	//Slave address
#define WHO_AM_I 0x0D			//Device ID register address --> register value 0x1A


void i2c_init(void);
void accelero_config(void);
int accelero_interrupt(void);
unsigned char accelero_test(void);
signed int GetAccelXVal(void);
signed int GetAccelYVal(void);
signed int GetAccelZVal(void);
unsigned char i2c_read(unsigned char reg_addr);
void i2c_write(unsigned char reg_addr, unsigned char reg_value);


#define STATUS 0x00
#define OUT_X_MSB 0x01
#define OUT_X_LSB 0x02
#define OUT_Y_MSB 0x03
#define OUT_Y_LSB 0x04
#define OUT_Z_MSB 0x05
#define OUT_Z_LSB 0x06
#define SYSMOD 0x0B				//bits [1:0] System Mode. Default value: 00: STANDBY mode
								//01: WAKE mode
								//10: SLEEP mode
#define INT_SOURCE 0x0C
#define WHO_AM_I 0x0D			//Device ID register address --> register value 0x1A
#define XYZ_DATA_CFG 0x0E		//Default 2g, no HP filter
#define CTRL_REG1 0x2A
#define CTRL_REG2 0x2B
#define CTRL_REG3 0x2C
#define CTRL_REG4 0x2D
#define CTRL_REG5 0x2E


#endif	/* #ifndef __ACCELERO_H */